package src.mian.java;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.text.SimpleDateFormat;


public class HDFSFileInfo {
    public static void main(String[] args) {
        String hdfsUri = "hdfs://192.168.254.100:8020"; // 替换成您的 HDFS URI
        Configuration conf = new Configuration();
        conf.set("fs.defaultFS", hdfsUri);
        try {
            FileSystem fs = FileSystem.get(conf);
            Path filePath = new Path("/test/hello.txt"); // 替换成您要查看的文件路径
            FileStatus fileStatus = fs.getFileStatus(filePath);

            System.out.println("File Path: " + fileStatus.getPath().toString());
            System.out.println("File Permission: " + fileStatus.getPermission());
            System.out.println("File Size: " + fileStatus.getLen() + " bytes");

            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println("File Creation Time: " + dateFormat.format(fileStatus.getModificationTime()));

            fs.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
